<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery-3.5.1.js"></script>
    <script src="../js/dateUtil.js"></script>
    <style>
        a{
            color: red;
        }
      #img img{
          width: 300px;
          height: 200px;
      }
        table{
            border-collapse: collapse;
        }
        tr{
            border:1px solid #2e6da4;
        }
    </style>
</head>
<body>
<a style="color: black" href="addImg.html">添加轮播</a>
<table>
       <tr>
           <td width="100px">编号</td>
           <td width="100px">名称</td>
           <td width="300px">图片</td>
           <td width="100px">跳转目标</td>
           <td width="200px">上传时间</td>
           <td width="100px">操作</td>
           <td></td>
       </tr>
</table>
<script>
    $(document).ready(function () {
        $.ajax({
            url:"../rotation?method=getImg",
            type:"post",
            dataType:"json",
            success:function (result) {
                var str="";
                $.each(result,function (index,item) {
                    str+="<tr>";
                    str+="<td>"+item.id+"</td>";
                    str+="<td>"+item.name+"</td>";
                    str+="<td id='img'><img src="+item.url+"></a></td>";
                    str+="<td>"+item.href+"</td>";
                    str+="<td>"+timestampToTime(item.date)+"</td>";
                    str+="<td>"+"<a style='color: black' href='editImg.html?id="+item.id+"'>修改</a><button class='delImg' id='"+item.id+"'>删除</button></td>";
                    str+="</tr>"
                })
                $("table").append(str);
            }
        })
        $(document).on("click",".delImg",function () {
            if(confirm("确定要删除吗？")){
                var id = $(this).attr("id");
                alert(id);
                $.ajax({
                    url:"../rotation",
                    data:{"method":"delete","id":id},
                    dateType:"json",
                    type:"post",
                    success:function (result) {
                        if(result=="SUCCESS"){
                            window.location.reload();
                        }else{
                            alert("删除失败")
                        }
                    }
                })
            }
        })
    })
</script>
</body>
</html>